/*底部按钮切换*/
function MallChange(x) {
    if (x == 1) {
        document.getElementById("img1").src = "images/model_boot/menu-2.png"
        document.getElementById("img2").src = "images/model_boot/me-1.png"
        document.getElementById("img3").src = "images/model_boot/cart-1.png"
        //document.getElementById("img4").src="images/classify_1.png"
        $("#change1").find("span").addClass("bot_focus");
        $("#change2").find("span").removeClass("bot_focus");
        $("#change3").find("span").removeClass("bot_focus");
        //$("#change4").find("span").removeClass("bot_focus");
    } else if (x == 2) {
        document.getElementById("img1").src = "images/model_boot/menu-1.png"
        document.getElementById("img2").src = "images/model_boot/me-2.png"
        document.getElementById("img3").src = "images/model_boot/cart-1.png"
        //document.getElementById("img4").src="images/classify_1.png"
        $("#change1").find("span").removeClass("bot_focus");
        $("#change2").find("span").addClass("bot_focus");
        $("#change3").find("span").removeClass("bot_focus");
        //$("#change4").find("span").removeClass("bot_focus");
    } else if (x == 3) {
        document.getElementById("img1").src = "images/model_boot/menu-1.png"
        document.getElementById("img2").src = "images/model_boot/me-1.png"
        document.getElementById("img3").src = "images/model_boot/cart-2.png"
        //document.getElementById("img4").src="images/classify_1.png"
        $("#change1").find("span").removeClass("bot_focus");
        $("#change2").find("span").removeClass("bot_focus");
        $("#change3").find("span").addClass("bot_focus");
        //$("#change4").find("span").removeClass("bot_focus");
    } else if (x == 4) {
        document.getElementById("img1").src = "images/model_boot/menu-1.png"
        document.getElementById("img2").src = "images/model_boot/me-1.png"
        document.getElementById("img3").src = "images/model_boot/cart-1.png"
        //document.getElementById("img4").src="images/classify_2.png"
        $("#change1").find("span").removeClass("bot_focus");
        $("#change2").find("span").removeClass("bot_focus");
        $("#change3").find("span").removeClass("bot_focus");
        //$("#change4").find("span").addClass("bot_focus");
    }
}

//根据不同状态选择显示隐藏
function show_hide(a, b, c) {
    var val = $(a).val()
    if ($(a).val() == 0) {
        $(c).show();
        $(a).val(1);
        $(b).bind("click", function () {
            $(c).hide();
            $(a).val(0);
        })
    } else {
        $(c).hide();
        $(a).val(0);
    }
};
//单击收起
function click_retract(id) {

    var state = document.getElementById(id).style;
    if (state.display == "block" || state.display == "") {
        state.display = 'none';
    } else if (state.display == "none") {
        state.display = 'block';
    }
}
//输入框提示不同内容
function input_alert(html, time) {
    if (!time) {
        time = 2000;
    }
    var float_element = $(".c-float-popWrap")
    var hei = $(window).height() / 2
    var top = $(document).scrollTop() + hei - 30;
    float_element.css({"top": top + "px"})
    $(".warnMsg").html(html)
    float_element.show()
    setTimeout(function () {
        float_element.hide()
    }, time);

}
//支付密码输入
function paymentpassword() {
    var $input = $(".fake-box input");
    $("#pwd-input").on("input", function () {
        var pwd = $(this).val().trim();
        for (var i = 0, len = pwd.length; i < len; i++) {
            $input.eq("" + i + "").val(pwd[i]);
        }
        $input.each(function () {
            var index = $(this).index();
            if (index >= len) {
                $(this).val("");
            }
        });
    });
}
//我的订单页不同入口设置不同区域active
function order_active(act, actid) {
    var active = $(act)
    var activeid = $(actid)
    active.addClass("active")
    activeid.addClass("active")
}
//页面加载动画函数
function pageLoad(page, time) {
    if (!time) {
        time = 300;
    }
    setTimeout(function () {
        $(".spinner").hide();
        $(page).fadeIn();
    }, time)
}
//模态框取消按钮函数
function dismiss() {
    $(".contain-no").click(function () {
        $(".contain-item").fadeOut();
        $(".contain-item1").fadeOut();
        $(".contain-item2").fadeOut();
    })
}


//点击其他地方隐藏
function hidename() {
    $(document).bind("click", function (e) {
        $('.djshow').fadeOut();
        //对document绑定一个影藏Div方法
    })
}
//购物车编辑操作
function cartGoodsEdit(editId, goodsEditId, goodsCompleteId, deleteId) {
    var edit = document.getElementById(editId);
    var edit_goods = $("." + goodsEditId);
    var edit_complete = $("." + goodsCompleteId);
    var deleteId = $("." + deleteId);
    var width_ = 6.4 / 6;
    if (edit.innerHTML == '编辑') {
        edit_goods.show();
        edit_complete.hide();
        deleteId.css({width: width_ + "rem"});
        edit.innerHTML = '完成';
    } else if (edit.innerHTML = '完成') {
        edit_goods.hide();
        edit_complete.show();
        deleteId.css({width: "0"});
        edit.innerHTML = '编辑';
    }
}
//购物车同步服务器时加载动画
function loadCart(show) {
    var loader = document.getElementById('loader');
    var hei = $(window).height();
    loader.style.height = hei + "px";
    if (show == true) {
        loader.style.zIndex = 1031;
        var loaderHtml = '';
        var spanLen = 12;
        loaderHtml += '<div class="loader-inner line-spin-fade-loader">'
        for (var i = 0; i < spanLen; i++) {
            loaderHtml += '<span></span>'
        }
        loaderHtml += '</div>'
        loader.innerHTML = loaderHtml;
        var spanDom = loader.getElementsByTagName("span");
        for (var j = 0; j < spanDom.length; j++) {
            var distance = 12;
            var angle = (360 / spanDom.length) * j;
            var _top = distance * Math.sin(2 * Math.PI * (angle / 360));
            var _left = distance * Math.cos(2 * Math.PI * (angle / 360));
            var infiniteTime = 0.02;
            setStyle(spanDom[j], {
                top: _top + "px",
                left: _left + "px",
                WebkitTransform: "rotate(" + angle + "deg)",
                //MsTransform: "rotate("+angle+"deg)",
                transform: "rotate(" + angle + "deg)",
                //WebkitAnimation: "line-spin-fade-loader 1.2s "+ infiniteTime*j+"s infinite ease-in-out",
                animation: "line-spin-fade-loader 0.24s " + infiniteTime * j + "s infinite ease-in-out",
                opacity: j * (1 / 18) + 0.3
            })
        }
        function setStyle(d, c) {
            for (name in c) {
                d.style[name] = c[name]
            }
        }
    } else {
        loader.style.zIndex = -1;
        loader.innerHTML = '';
    }
};
//余额支付键盘控制
function paymentNum(paymentFun) {
    var numDom = document.getElementById('paymentNum');
    var td = numDom.getElementsByTagName('td');
    var paymentPassword = '';
    var paymentUl = $("#payment_circle");
    var payment_circle = paymentUl.find("li");
    var keyHei = document.querySelector('.payment_keyboard').offsetHeight;
    $(".payment_keyboard").css({transform: "translateY(" + keyHei + "px)"}, {"-webkit-transform": "translateY(" + keyHei + "px)"});
    for (var i = 0; i < td.length; i++) {
        td[i].addEventListener('touchstart', function (e) {
            this.moved = false;
            this.theTarget = document.elementFromPoint(e.targetTouches[0].clientX, e.targetTouches[0].clientY);
            if (this.theTarget.nodeType == 3) this.theTarget = theTarget.parentNode;
            this.theTarget.className += ' pressed';
        });
        td[i].addEventListener('touchmove', function (e) {
            this.moved = true;
            this.theTarget.className = this.theTarget.className.replace(/ ?pressed/gi, '');
        });
        td[i].addEventListener('touchend', function (e) {
            if (!this.moved && this.theTarget) {
                this.theTarget.className = this.theTarget.className.replace(/ ?pressed/gi, '');
                var self = this;
                if (self.id == 'paymentCancel') {
                    length = paymentPassword.length;
                    if (length > 0) {
                        payment_circle[length - 1].removeAttribute('class', 'active');
                    }
                    paymentPassword = paymentPassword.substring(0, paymentPassword.length - 1);
                } else {
                    var length = paymentPassword.length;
                    if (length < 6) {
                        payment_circle[length].setAttribute('class', 'active');
                        paymentPassword += self.innerText;
                    }
                    if (paymentPassword.length == 6) {
                        $("#paymentTxt").val(paymentPassword);
                        var paymentchange = paymentFun;
                        paymentchange();
                    }
                }
                e.stopPropagation();
            }
        });
    }
    $(".payment_page_logo").click(function (e) {
        keyHei = document.querySelector('.payment_keyboard').offsetHeight;
        $(".payment-pages").css({opacity: 0});
        setTimeout(function () {
            $(".payment-pages").css({zIndex: -1});
        }, 200)
        $(".payment_keyboard").css({transform: "translateY(" + keyHei + "px)"}, {"-webkit-transform": "translateY(" + keyHei + "px)"});
        payment_circle.removeClass('active');
        paymentPassword = '';
        e.stopPropagation();
    });
    $(".payment_keyboard_back").click(function (e) {
        keyHei = document.querySelector('.payment_keyboard').offsetHeight;
        $(".payment_keyboard").css({transform: "translateY(" + keyHei + "px)"}, {"-webkit-transform": "translateY(" + keyHei + "px)"});
        e.stopPropagation();
    })
    paymentUl.click(function (e) {
        $(".payment_keyboard").css({transform: "translateY(0px)"}, {"-webkit-transform": "translateY(0px)"});
        e.stopPropagation();
    })
}
//cookie设置读取和删除
//设置
function setCookie(name, value, day) {
    var Days = day;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
//读取
function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg)) {
        return unescape(arr[2]);
    }
    else {
        return null;
    }
}
//删除
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null){
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
    }
}
//下单页面样式控制
function placeOrderEnterCss(position1,speed1,position2,speed2){
    $(".payment_show").css({transform:"translateX("+position1+"px)",WebkitTransform:"translateX("+position1+"px)",WebkitTransition: "all "+speed1+"ms ease",transition: "all "+speed1+"ms ease"})
    $(".addr_hide").css({transform:"translateX("+position2+"px)",WebkitTransform:"translateX("+position2+"px)",WebkitTransition: "all "+speed2+"ms ease",transition: "all "+speed2+"ms ease"})
}
//判断浏览器类型
function BrowserType()
{
    var userAgent = navigator.userAgent;
    var isWX = userAgent.indexOf("MicroMessenger") > -1;
    var isALI = userAgent.indexOf("AlipayClient") > -1;
    if(isWX){
        return "WX";
    }
    if(isALI){
        return "ALI";
    }
    return "YUE";
}